package org.dromara.system.service.impl;

import org.dromara.system.service.SysTenantService;
import org.dromara.system.pojo.entity.SysTenantDO;
import org.dromara.system.pojo.bo.SysTenantBO;
import org.dromara.system.pojo.qo.SysTenantQO;
import org.dromara.system.pojo.vo.SysTenantVO;
import org.dromara.system.mapper.SysTenantMapper;
import org.springframework.stereotype.Service;

import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.utils.BeanCopyUtils;

import java.util.List;

/**
 * 租户表 服务层实现。
 *
  * @author mkj
  * @since 2024-07-21
 */
@RequiredArgsConstructor
@Service
public class SysTenantServiceImpl  implements SysTenantService {

    private final SysTenantMapper sysTenantMapper;

    @Override
    public boolean add(SysTenantBO sysTenantBO) {
        SysTenantDO sysTenantDO = BeanCopyUtils.copy(sysTenantBO, SysTenantDO.class);
        return sysTenantMapper.insert(sysTenantDO) > 0;
    }

    @Override
    public boolean remove(Long id) {
        return sysTenantMapper.deleteById(id) > 0;
    }

    @Override
    public boolean update(SysTenantBO sysTenantBO) {
        SysTenantDO sysTenantDO = BeanCopyUtils.copy(sysTenantBO, SysTenantDO.class);
        return sysTenantMapper.update(sysTenantDO) > 0;
    }

    @Override
    public List<SysTenantVO> list(SysTenantQO sysTenantQO) {
        SysTenantDO sysTenantDO = BeanCopyUtils.copy(sysTenantQO, SysTenantDO.class);
        QueryWrapper queryWrapper = QueryWrapper.create(sysTenantDO);
        return sysTenantMapper.selectListByQueryAs(queryWrapper, SysTenantVO.class);
    }

    @Override
    public SysTenantVO getInfo(@PathVariable Long id) {
        SysTenantDO sysTenantDO = sysTenantMapper.selectOneById(id);
        if (sysTenantDO == null){
            return null;
        }
        return BeanCopyUtils.copy(sysTenantDO, SysTenantVO.class);
    }

    @Override
    public Page<SysTenantVO> page(SysTenantQO page) {
        return sysTenantMapper.paginateAs(page.getPageNumber(), page.getPageSize(), QueryWrapper.create(page), SysTenantVO.class);
    }

}

